﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Threading;
using GalaSoft.MvvmLight;
using ProjectWizardManagementv1.Infrastructure.Abstract;
using ProjectWizardManagementv1.ViewModels.Concrete;

namespace ProjectWizardManagementv1.Infrastructure.Concrete
{
    public class WpfFileSystemHandler : IFileSystemWatcherHandler
    {
        public FileExplorerViewModel Files { get; set; }
        public Action RaisePropertyChangedAction;

        public WpfFileSystemHandler(FileExplorerViewModel files)
        {
            this.Files = files;
            //this.RaisePropertyChangedAction = _action;
        }

        public void OnFileCreated(object sender, FileSystemEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
            {
                var file = FileSystemFactory.ConstructFileHierarchy(e.FullPath);
               // Files.AddFileToParentDirectory(file);
                RaisePropertyChangedAction.Invoke();
                //RaisePropertyChanged("Files");
            }));
        }

        public void OnFileDeleted(object sender, FileSystemEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
            {
                //Files.RemoveFileByPath(e.FullPath);
                RaisePropertyChangedAction.Invoke();
               // RaisePropertyChanged("Files");
            }));
        }

        public void OnFileRenamed(object sender, RenamedEventArgs e)
        {

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
            {
               // Files.RenameFile(e.OldFullPath, e.FullPath);
                RaisePropertyChangedAction.Invoke();
                //RaisePropertyChanged("Files");
            }));
        }
    }
}
